import logging

from django.http import HttpResponse

# Get an instance of a logger
from TacticNuke.TacticNuke import TacticNuke

logger = logging.getLogger(__name__)

def build(request):
    logger.debug(msg='Django View Method build Debug:run')

    name = None
    basepath = None
    master_basepath = None
    master_nukepath = None

    if request.method != 'POST':
        logger.debug('Django View Method build Debug:only support post')
        return HttpResponse('only post',status=400)

    try:
        name = request.POST['name']
        basepath = request.POST['basepath']
        master_basepath = request.POST['master_basepath']
        master_nukepath = request.POST['master_nukepath']
    except Exception, e:
        logger.debug('Django View Method build Debug:post value has empty')
        logger.debug(e)
        return HttpResponse('some value empty', status=400)


    # def build(self, name, basepath, master_basepath, master_nukepath):
    result = None
    try:
        logger.debug('Django View Method build Debug:[name]=' + str(name))
        logger.debug('Django View Method build Debug:[basepath]=' + str(basepath))
        logger.debug('Django View Method build Debug:[master_basepath]=' + str(master_basepath))
        logger.debug('Django View Method build Debug:[master_nukepath]=' + str(master_nukepath))
        nuke = TacticNuke()
        result = nuke.build(name=name, basepath=basepath, master_basepath=master_basepath,master_nukepath=master_nukepath)
    except Exception, e:
        result = 'Exception:' + str(e)

    logger.debug('Django View Method build Debug:[result]=' + str(result))

    return HttpResponse(result)